package db;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Description:
 * @Author: xiaobing
 * @system name: 工作流引擎
 * @copyright：长安新生（深圳）金融投资有限公司
 * @Date: Created in  2018/9/26 17:43
 */
public class TruncateGitCountDao {


    private static Connection conn = null;

    private static Statement pstm = null;

    private static final Logger logger = LoggerFactory.getLogger(GitCountDao.class);


    /**
     * @Author: xiaobing
     * @Description: gitCount表清空
     * @Date: 2018/9/26
     */
    public static void gitCountTruncate() {
        logger.info("开始清空gitCount表数据！");
        try {
            if(conn == null){
                conn=DBHelper.getConnection();
            }
            String sql = "TRUNCATE TABLE git_count";
            pstm = conn.createStatement();
            pstm.execute(sql);
            logger.info("gitCount表清空完成");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("gitCount表清空失败！");
        } finally {
            try {
                // 这里最好要先判断是否为空，不为空了，才去关闭。
                // 而且要从小到大的关闭，顺序不能乱
                if (pstm != null) {
                    pstm.close();
                }
                /*if (conn != null)
                    conn.close(); */    //注意：如果后续还要使用connection，则不用关闭
            } catch (SQLException e)
            {
                e.printStackTrace();
            }
        }
    }
}
